<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="${classPath}.dao.${table.className}Dao">
	<resultMap id="${table.className}ResultMap" type="${classPath}.entity.${table.className}${entitySuffix}">
		<#list columns as column>
		<#if column.isPrimary>
		<id column="${column.columnName}" property="${column.fieldName}" jdbcType="${column.typeName}" />
		<#else>
		<result column="${column.columnName}" property="${column.fieldName}" jdbcType="${column.typeName}" />
		</#if>
		</#list>
	</resultMap>
	
	<!--根据条件查询${table.remark}列表 -->
	<select id="select${table.className}List" parameterType="${classPath}.param.${table.className}Param" resultMap="${table.className}ResultMap">
		SELECT
			<#list columns as column>
			t.${column.columnName}<#if column_has_next>,</#if>
			</#list>
		from ${table.tableName} t
		<trim prefix="where" suffixOverrides="and">
			<#list columns as column>
			<#if column.javaTypeName =="Timestamp">
			<if test="${column.fieldName}Start !=null ">t.${column.columnName} &gt;= ${braceStart}${column.fieldName}Start${braceEnd} and </if>
			<if test="${column.fieldName}End !=null ">t.${column.columnName} &lt;= ${braceStart}${column.fieldName}End${braceEnd}  and </if>
			<#else>
			<if test="${column.fieldName}!=null and ${column.fieldName}!=''">
				t.${column.columnName}=${braceStart}${column.fieldName}${braceEnd} and
			</if>
			</#if>
			</#list>
		</trim>
		<if test="orderField==null or orderField=='' or orderDirection==null or orderDirection==''">
			order by t.create_time desc 
		</if>
		<if test="orderField!=null and orderField!='' and orderDirection!=null and orderDirection!=''">
			order by ${braceStart}orderField${braceEnd} ${braceStart}orderDirection${braceEnd} 
		</if>
		limit ${braceStart}startNum${braceEnd},${braceStart}pageSize${braceEnd}
	</select>
	
	<!--根据条件查询${table.remark}数量 -->
	<select id="select${table.className}List_count" parameterType="${classPath}.param.${table.className}Param" resultType="int">
		select count(1) from ${table.tableName} t
		<trim prefix="where" suffixOverrides="and">
			<#list columns as column>
			<#if column.javaTypeName =="Timestamp">
			<if test="${column.fieldName}Start !=null ">t.${column.columnName} &gt;= ${braceStart}${column.fieldName}Start${braceEnd} and </if>
			<if test="${column.fieldName}End !=null ">t.${column.columnName} &lt;= ${braceStart}${column.fieldName}End${braceEnd}  and </if>
			<#else>
			<if test="${column.fieldName}!=null and ${column.fieldName}!=''">
				t.${column.columnName}=${braceStart}${column.fieldName}${braceEnd} and
			</if>
			</#if>
			</#list>
		</trim>	
	</select>
	
	<!--根据主键查询${table.remark}信息 -->
	<select id="select${table.className}ById" parameterType="string" resultMap="${table.className}ResultMap">
		SELECT
			<#list columns as column>
			t.${column.columnName}<#if column_has_next>,</#if>
			</#list>
		from ${table.tableName} t
		<trim prefix="where" suffixOverrides="and">
			<#list columns as column>
			<#if column.isPrimary>
				${column.columnName}=${braceStart}${column.fieldName}${braceEnd} and
			</#if>
			</#list>
		</trim>
	</select>
	
	<!-- 更新${table.remark}信息 -->
	<insert id="insert${table.className}" parameterType="${classPath}.entity.${table.className}${entitySuffix}">
		insert into ${table.tableName} (
		<#list columns as column>
		${column.columnName}<#if column_has_next>,</#if>
		</#list>
		) VALUES (
		<#list columns as column>
		${braceStart}${column.fieldName}${braceEnd}<#if column_has_next>,</#if>
		</#list>
		)
	</insert>
	
	<!-- 更新${table.remark}信息 -->
	<update id="update${table.className}ById" parameterType="${classPath}.entity.${table.className}${entitySuffix}">
		update ${table.tableName} 
		<set>
			<#list columns as column>
			<#if !column.isPrimary>
			<if test="${column.fieldName}!=null">${column.columnName}=${braceStart}${column.fieldName},jdbcType=${column.typeName}${braceEnd},</if>
			</#if>
			</#list>
		</set>
		<trim prefix="where" suffixOverrides="and">
			<#list columns as column>
			<#if column.isPrimary>
				${column.columnName}=${braceStart}${column.fieldName}${braceEnd} and
			</#if>
			</#list>
		</trim>
	</update>
	
	<!-- 根据ID删除${table.remark}信息 -->
	<delete id="delete${table.className}ById" parameterType="string">
		update ${table.tableName}
		set data_status=1
		<trim prefix="where" suffixOverrides="and">
			<#list columns as column>
			<#if column.isPrimary>
				${column.columnName}=${braceStart}${column.fieldName}${braceEnd} and
			</#if>
			</#list>
		</trim>
	</delete>
</mapper>